package com.zb.vo;

import com.zb.entity.ZjUserSet;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.util.Date;

/**
 * @Author WEN
 * @Date 2023/7/26 0026
 **/
@Data
@ApiModel("用户设置实体封装")
public class UserSetVo {
    @NotNull(message = "用户设置ID不能为空")
    @ApiModelProperty(value = "用户设置ID，必传", required = true, example = "")
    private Long id;

    @NotBlank(message = "默认编码不能为空")
    @Length(max = 2, message = "默认编码字符长度限制在2个以内")
    @Pattern(regexp = "^[A-Za-z1-9]{1,2}$", message = "默认编码不支持中文输入！")
    @ApiModelProperty(value = "默认编码", required = true, example = "US")
    private String code;

    @NotNull(message = "知识库查看权限选项不能为空")
    @ApiModelProperty(value = "知识库查看权限：false-查看所有，true-根据客户分类权限查看", required = true, example = "false")
    private Boolean selectKnowledgeAuthor;

    @ApiModelProperty(value = "用户等级表ID，默认等级", example = "0")
    private Long levelId;

    @NotNull(message = "客户端是否开启必须登录项不能为空")
    @ApiModelProperty(value = "客户移动端是否开启必须登录：false-关闭，true-开启", required = true, example = "false")
    private Boolean mobileHasLogin;

    @ApiModelProperty(value = "创建时间", hidden = true)
    private Date createTime;

    @ApiModelProperty(value = "更新时间", hidden = true)
    private Date updateTime;

    public static UserSetVo beanToVo(ZjUserSet userSet) {
        UserSetVo vo = new UserSetVo();
        BeanUtils.copyProperties(userSet, vo);
        vo.setCreateTime(userSet.getGmtCreate());
        vo.setUpdateTime(userSet.getGmtUpdate());
        return vo;
    }

    public static ZjUserSet voToBean(UserSetVo vo) {
        ZjUserSet userSet = new ZjUserSet();
        BeanUtils.copyProperties(vo, userSet);
        return userSet;
    }
}
